/*
创建新的设备类别

安装次模块，将
    在/sys/class/生成dev-class目录
*/

#include "linux/init.h"
#include "linux/module.h"
#include "linux/device.h"

static const char *dev_class_name = "dev-class";
static struct class *dev_class = NULL;

static int __init dev_class_init(void)
{
    printk("file=%s,fun=%s,line=%d\n", __FILE__, __FUNCTION__, __LINE__);

    dev_class = class_create(THIS_MODULE, dev_class_name);
    if (IS_ERR(dev_class))
    {
        printk("class_create error\n");
        return -1;
    }
    printk("class_create succeed\n");

    return 0;
}

static void __exit dev_class_exit(void)
{
    printk("file=%s,fun=%s,line=%d\n", __FILE__, __FUNCTION__, __LINE__);

    if (dev_class)
    {
        class_destroy(dev_class);
        dev_class = NULL;

        printk("class_destroy succeed\n");
    }
}

module_init(dev_class_init);
module_exit(dev_class_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("lxz");
